/**
 * 初始化
 */
const create = async () => {
    global.灯组 = DeviceManager.createLight({
        name: '灯组',
        group: true,
    })
}

/**
 * 初始化
 */
const init = async () => {
    const state = {
        switch: 123,
    };
    saveState(state)
}

/**
 * 上报
 */
const subscribe = ({ data, device, deviceIndex, state }) => {

    console.log(device === global.灯组, '11111111111')
    console.log('上报的数据', data, device, deviceIndex, state)
}

const everyFiveSeconds = ({ data, state }) => {
    console.log('5秒上报的数据', data, state)
    global.灯组.getSwitch().then((res) => {
        console.log('获取加湿器开关 成功 :>> ', res);
        console.log('1111', res.code == 200)
        if (res[0].code == 200) {
            console.log('2222', global.灯, res[0].data)
            global.灯组.setSwitch(!res[0].data).then((res) => {
                console.log('设置加湿器开关 成功 :>> ', res);
            }).catch((err) => {
                console.log('设置加湿器开关 失败 :>> ', err);
            });
        }
    }).catch((err) => {
        console.log('获取加湿器开关 失败 :>> ', err);
    });

    return 'everyFiveSeconds 执行成功';
}
